package com.ocean.product.service.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ocean.product.domain.TSDocument;
import com.ocean.product.mapper.TSDocumentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ocean.product.mapper.TSAttachmentMapper;
import com.ocean.product.domain.TSAttachment;
import com.ocean.product.service.ITSAttachmentService;
import com.ocean.common.core.text.Convert;

/**
 * 项目附件父表Service业务层处理
 *
 * @author ocean
 * @date 2023-02-06
 */
@Service
public class TSAttachmentServiceImpl implements ITSAttachmentService
{
    @Autowired
    private TSAttachmentMapper tSAttachmentMapper;
    @Autowired
    private TSDocumentMapper documentMapper;

    /**
     * 查询项目附件父表
     *
     * @param ID 项目附件父表主键
     * @return 项目附件父表
     */
    @Override
    public TSAttachment selectTSAttachmentByID(String ID)
    {
        return tSAttachmentMapper.selectTSAttachmentByID(ID);
    }

    /**
     * 查询项目附件父表列表
     *
     * @param tSAttachment 项目附件父表
     * @return 项目附件父表
     */
    @Override
    public List<TSAttachment> selectTSAttachmentList(TSAttachment tSAttachment)
    {
        List<TSDocument> documentList = documentMapper.selectTSDocumentList(new TSDocument());
        Map<String, TSDocument> map = documentList.stream().collect(Collectors.toMap(TSDocument::getId, d -> d));
        List<TSAttachment> result = tSAttachmentMapper.selectTSAttachmentList(tSAttachment);
        result.stream().forEach(a->a.setDocument(map.get(a.getID())));
        return result;
    }

    /**
     * 新增项目附件父表
     *
     * @param tSAttachment 项目附件父表
     * @return 结果
     */
    @Override
    public int insertTSAttachment(TSAttachment tSAttachment)
    {
        return tSAttachmentMapper.insertTSAttachment(tSAttachment);
    }

    /**
     * 修改项目附件父表
     *
     * @param tSAttachment 项目附件父表
     * @return 结果
     */
    @Override
    public int updateTSAttachment(TSAttachment tSAttachment)
    {
        return tSAttachmentMapper.updateTSAttachment(tSAttachment);
    }

    /**
     * 批量删除项目附件父表
     *
     * @param IDs 需要删除的项目附件父表主键
     * @return 结果
     */
    @Override
    public int deleteTSAttachmentByIDs(String IDs)
    {
        return tSAttachmentMapper.deleteTSAttachmentByIDs(Convert.toStrArray(IDs));
    }

    /**
     * 删除项目附件父表信息
     *
     * @param ID 项目附件父表主键
     * @return 结果
     */
    @Override
    public int deleteTSAttachmentByID(String ID)
    {
        return tSAttachmentMapper.deleteTSAttachmentByID(ID);
    }
}
